<template>
    <!-- 需要设置编辑区域高度 -->
    <pc-index ref="makingform" style="height: 900px;" preview generate-code generate-json>
        <template slot="action">
            <el-button @click="_SaveCardForm">保存</el-button>
        </template>
    </pc-index>

</template>

<script>
import PcIndex from '@/components/formMake2/setmoban'
import { SaveCardForm } from '@/api/api'
export default {
    components: {
        PcIndex
    },
    methods: {
        _SaveCardForm() {
            const formid = this.$route.query.formId
            // 保存时判断是否时导航栏组件 如果是删除其组件数据里的options信息
            const getData = this.$refs.makingform.getJSON()
            const widgetForm = getData.widgetForm
            if (widgetForm.list) {
                widgetForm.list.map(function(item, index) {
                    if (item.options.menuId) {
                        item.options.options = []
                    }
                })
            }
            let data;
            if(widgetForm.config.radio=='moban'){
                data = [
                    {
                        formid: 'Module,'+widgetForm.config.mobanName,
                        id: getData.id,
                        jsonstr: JSON.stringify((widgetForm))
                    }
                ]
            } else {
                data = [
                    {
                        formid: formid,
                        id: getData.id,
                        jsonstr: JSON.stringify((widgetForm))
                    }
                ]
            }
           
            SaveCardForm(data)
                .then(res => {
                    if (res.rcode === '0000') {
                        this.$notify({
                            title: '成功',
                            message: '保存成功',
                            type: 'success'
                        })
                        if(widgetForm.config.radio=='moban'){
                            this.$refs.makingform._getCardForm();
                        }
                    } else {
                        this.$notify({
                            title: '失败',
                            message: res.desc,
                            type: 'errow'
                        })
                    }
                })
        }
    }
}
</script>

